package com.freshcity.page.help
{
	import com.freshcity.component.FLabel;
	import com.freshcity.component.container.Component;
	import com.freshcity.core.OpCodes;
	import com.freshcity.manager.MsgManager;
	import com.freshcity.utils.StringUtil;
	import com.freshcity.wait.GainWealthWin;
	import com.freshcity.wait.IntroTxt;
	import com.greensock.TweenLite;
	import com.greensock.TweenMax;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.text.TextField;

	public class GainWealthDesc extends Component
	{
		private var back:GainWealthWin;

		public function GainWealthDesc(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0)
		{
			this.visible=false;
			super(parent, xpos, ypos);
			ExternalInterface.addCallback('share4RewardComplete', sendShareReward);

			var sp:Sprite = new IntroTxt();
			back.panel.source = sp;			
			
			back.inviteBtn.addEventListener(MouseEvent.CLICK, onInviteBtnHandler);
			back.shareBtn.addEventListener(MouseEvent.CLICK, onShareBtnHandler);
			//back.feedbackBtn.addEventListener(MouseEvent.CLICK, onLink);
		}


		private function sendShareReward(result:Boolean):void
		{
			main.commu.send(OpCodes.SHARE_REWARD, {}, onShareReward);
		}

		private function onShareReward(data:*):void
		{
			if (data == true)
			{
				back.shareBtn.enabled=false;
				main.commu.unRegister(OpCodes.SHARE_REWARD);
				main.msg.showPopUpMsg("因为分享,赢得五枚玫瑰。", MsgManager.COOL, 2);
				main.msg.showFixRollMsg("成功完成今日分享,赢得五枚玫瑰。");
			}
			else
			{
				main.msg.showRollTipsMsg(data);
			}
		}

		protected function onShareBtnHandler(event:MouseEvent):void
		{
			ExternalInterface.call("shareFeed", "welcome");
		}

		protected function onInviteBtnHandler(event:MouseEvent):void
		{
			var u:String=main.user.id;
			ExternalInterface.call("showPopupInvite", u);
		}

		override protected function addChildren():void
		{
			super.addChildren();
			back=new GainWealthWin();
			addChild(back);
		}

		override public function draw():void
		{
			super.draw();
			if (main.user.isapp == 'true')
			{
				if (main.user.canShare == 'false')
				{
					back.shareBtn.visible=false;
				}
				else
				{
					back.shareBtn.visible=true;
				}
				back.inviteBtn.visible=true;
				//back.feedbackBtn.visible=false;
			}
			else
			{
				back.inviteBtn.visible=false;
				back.shareBtn.visible=false;
			}
		}
	}
}